/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sqlserver;

import Database.Table;
import java.awt.Component;
import javax.swing.JComboBox;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

/**
 *
 * @author PHAMDANH
 */
public class ComboBoxCellRenderer extends JComboBox implements TableCellRenderer 
{
    private Table table;
    public ComboBoxCellRenderer(String[] items, Table table) 
    {
        super(items);
        this.table = table;
    }

    @Override
    public Component getTableCellRendererComponent(JTable jtable, Object value, boolean isSelected, 
                                                   boolean hasFocus, int row, int column) 
    {
        if(value!=null)
        {
            boolean flag=true;
            if(table.getColumns().size()>row)
            {
                if("String".equals(value.toString()))
                {
                    flag = table.getColumns().get(row).setType(String.class);                                        
                }
                else
                    if("Integer".equals(value.toString()))
                    {
                        flag = table.getColumns().get(row).setType(Integer.class);                                                            
                    }                     
            } 
            if(flag)
                setSelectedItem(value.toString());  
        }
        else
            setSelectedItem("String");                  
        return this;
    }
   
}
